<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<c-rt:if test="${!empty param.query}">


${pu:reqSet('pageableTag', pu:pageableTag('index', 20, 10)) }
${pu:criteriaForName('com.yaodian100.ec.order.entity.ServiceOrders') }
${pu:criteriaAdd(pu:criteria('eq', 'srcType', pu:toInteger('1'))) }
${pu:criteriaAdd(pu:criteria('eq', 'orderId', pu:emptyToNull(param.orderId))) }
${pu:criteriaAdd(pu:criteria('eq', 'serviceId', pu:emptyToNull(param.serviceId))) }
${pu:criteriaAdd(pu:criteria('eq', 'orderSt', pu:emptyToNull(param.orderSt))) }
<%--
<c-rt:if test="${empty param.orderSt}">
${pu:criteriaAdd(pu:criteria('eq', 'orderSt', '00')) }
</c-rt:if>
--%>
${pu:criteriaAdd(pu:criteria('eq', 'loginId', pu:emptyToNull(param.loginId)))}
${pu:criteriaAdd(pu:criteria('eq', 'receiverEmail', pu:emptyToNull(param.receiverEmail))) }
${pu:criteriaAdd(pu:criteria('eq', 'receiverMobile', pu:emptyToNull(param.receiverMobile))) }
${pu:criteriaAdd(pu:criteria('eq', 'receiverPhone', pu:emptyToNull(param.receiverPhone))) }
<c-rt:if test="${!empty param.startDate}">
<c-rt:set var="startDate">
${param.startDate } ${param.startHour }:${param.startMinute }
</c-rt:set>
${pu:criteriaAdd(pu:criteria('ge', 'createDate', pu:toDate(pu:emptyToNull(startDate), 'yyyy-MM-dd HH:mm'))) }
</c-rt:if>
<c-rt:if test="${!empty param.endDate}">
<c-rt:set var="endDate">
${param.endDate } ${param.endHour }:${param.endMinute }
</c-rt:set>

${pu:criteriaAdd(pu:criteria('le', 'createDate', pu:toDate(pu:emptyToNull(endDate), 'yyyy-MM-dd HH:mm'))) }
</c-rt:if>
${pu:criteriaAdd(pu:criteriaIn('reason', pu:toArray(pu:emptyToNull(paramValues.reason)))) }
${pu:criteriaAdd(pu:criteria('eq', 'callInOrOut', pu:emptyToNull(param.callInOrOut))) }
${pu:criteriaAddOrder(pu:criteriaOrderDesc('createDate')) }
<span style="color:red">
<%--
<c-rt:if test="${user.group.code==crmLine2}">
--%>
<c-rt:if test="${pu:isCRMManager(pu:username())}">
	<c-rt:if test="${empty param.orderId && empty param.serviceId}">
	<c-rt:choose>
	<c-rt:when test="${empty param.startDate && empty param.endDate}">
	请填订单编号或退货编号，日期区间
	</c-rt:when>
	<c-rt:otherwise>
	${pu:reqSet('results', pu:criteriaResult(pageableTag)) }
	</c-rt:otherwise>
	</c-rt:choose>
	</c-rt:if>
	<c-rt:if test="${!empty param.orderId || !empty param.serviceId}">
	
	</c-rt:if>
</c-rt:if>
<c-rt:if test="${!pu:isCRMManager(pu:username())}">
	<c-rt:choose>
	<c-rt:when test="${empty param.orderId && empty param.serviceId && empty param.loginId && empty param.receiverEmail && empty param.receiverMobile && empty param.receiverPhone}">
	订单编号／退货编号／会员帐号／会员email／会员手机／会员固定电话 至少需填一个
	</c-rt:when>
	<c-rt:otherwise>
	${pu:reqSet('results', pu:criteriaResult(pageableTag)) }
	</c-rt:otherwise>
	</c-rt:choose>
</c-rt:if>
</span>
</c-rt:if>
<script>

function exportCsv(){
	var hasSelected=false;
	$('.serviceIds').each(function(){
		if($(this).attr('checked')){
			hasSelected=true;
		}
	});
	if(hasSelected){
	document.exportAndBatchForm.action='<c-rt:url value="/serviceOrder/export.do"/>';
	document.exportAndBatchForm.submit();	
	}else{
		alert('请选择项目');
	}
}
function batchConfirm(){
	var hasSelected=false;
	$('.serviceIds').each(function(){
		if($(this).attr('checked')){
			hasSelected=true;
		}
	});
	if(hasSelected){
	document.exportAndBatchForm.action='<c-rt:url value="/serviceOrder/batchConfirm.do"/>';
	document.exportAndBatchForm.submit();
	}else{
		alert('请选择项目');
	}
}
</script>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/ecadmin/css/smoothness.datepick.css" />
<script>
$(function(){
	$('#startDate').datepick({dateFormat:'yy-mm-dd'});
	$('#endDate').datepick({dateFormat:'yy-mm-dd'});
});
function line1CR(){
	if(document.queryForm.orderId.value=='' &&
	   document.queryForm.serviceId.value=='' &&
	   document.queryForm.loginId.value=='' &&
	   document.queryForm.receiverEmail.value=='' &&
	   document.queryForm.receiverMobile.value=='' &&
	   document.queryForm.receiverPhone.value==''){
		alert('订单编号／退货编号／会员帐号／会员email／会员手机／会员固定电话 至少需填一个');
	}else{
		document.queryForm.submit();
	}
}
function cRManager(){
	if(document.queryForm.orderId.value=='' && document.queryForm.serviceId.value==''){
		if(document.queryForm.startDate.value=='' ||
		   document.queryForm.endDate.value==''){
			alert('请填订单编号或退货编号，日期区间');
		}else{
			document.queryForm.submit();
		}
	}else{
		document.queryForm.submit();
	}
}
</script>
${pu:reqSet('user', pu:user()) }
<c-rt:if test="${pu:isCRMManager(pu:username())}">
<%--客服主管 --%>
${pu:reqSet('queryMethod', 'cRManager()') }
</c-rt:if>
<c-rt:if test="${!pu:isCRMManager(pu:username())}">
${pu:reqSet('queryMethod', 'line1CR()') }
</c-rt:if>
<form name="queryForm" action="<c-rt:url value="/serviceOrder/page.do"/>" method="post">
<input type="hidden" name="query" value="true"/>
<input type="hidden" name="iamlazy" value="returnList"/>
<table>
<tr>
	<td>订单编号：<input type="text" name="orderId" value="${param.orderId }"/></td>
	<td>退货编号：<input type="text" name="serviceId" value="${param.serviceId }"/></td>
	<td>退货状态：
	<select name="orderSt">
	<option value="">請選擇</option>
		<option value="00" ${param.orderSt=='00'?'selected="selected"':'' }>审核中</option>
		<option value="10" ${param.orderSt=='10'?'selected="selected"':'' }>申请中</option>
		<option value="20" ${param.orderSt=='20'?'selected="selected"':'' }>退款处理中</option>
		<option value="30" ${param.orderSt=='30'?'selected="selected"':'' }>异常</option>
		<option value="50" ${param.orderSt=='50'?'selected="selected"':'' }>逾期</option>
		<option value="60" ${param.orderSt=='60'?'selected="selected"':'' }>商品退回</option>
		<option value="70" ${param.orderSt=='70'?'selected="selected"':'' }>失败</option>
		<option value="80" ${param.orderSt=='80'?'selected="selected"':'' }>取消</option>
		<option value="90" ${param.orderSt=='90'?'selected="selected"':'' }>完成</option>
	</select>
	</td>
	<td>call in/ call out:
		<select name="callInOrOut">
			<option value="">請選擇</option>
			<option value="in" ${param.callInOrOut=='in'?'selected="selected"':'' }>call in</option>
			<option value="out" ${param.callInOrOut=='out'?'selected="selected"':'' }>call out</option>
		</select>
	</td>
</tr>
<tr>
	<td>会员帐号：<input type="text" name="loginId" value="${param.loginId }"/></td>
	<td>会员email：<input type="text" name="receiverEmail" value="${param.receiverEmail }"/></td>
	<td>收货人手机：<input type="text" name="receiverMobile" value="${param.receiverMobile }"/></td>
	<td>收货人固定电话：<input type="text" name="receiverPhone" value="${param.receiverPhone }"/></td>
</tr>
<tr>
	<td>日期起：<input type="text" id="startDate" size="12" name="startDate" value="${param.startDate }"/>
		<select name="startHour">
		<c-rt:forEach begin="0" end="23" step="1" varStatus="s">
		<c-rt:set var="startHour">
		<c-rt:if test="${s.index<10}">0</c-rt:if>${s.index }
		</c-rt:set>
		
		<option ${param.startHour==startHour?'selected="selected"':'' } value="${startHour }">${startHour }</option>
		</c-rt:forEach>
		</select>
		<select name="startMinute">
		<c-rt:forEach begin="0" end="60" step="10" varStatus="s">
		<c-rt:set var="startMinute">
		<c-rt:if test="${s.index<10}">0</c-rt:if>${s.index }
		</c-rt:set>
		<option ${param.startMinute==startMinute?'selected="selected"':'' } value="${startMinute }">${startMinute }</option>
		</c-rt:forEach>
		</select>
	</td>
	<td>日期迄：<input type="text" id="endDate" size="12" name="endDate" value="${param.endDate }"/>
	<select name="endHour">
		<c-rt:forEach begin="0" end="23" step="1" varStatus="s">
		<c-rt:set var="endHour">
		<c-rt:if test="${s.index<10}">0</c-rt:if>${s.index }
		</c-rt:set>
		<option ${param.endHour==endHour?'selected="selected"':'' } value="${endHour }">${endHour }</option>
		</c-rt:forEach>
		</select>
		<select name="endMinute">
		<c-rt:forEach begin="0" end="60" step="10" varStatus="s">
		<c-rt:set var="endMinute">
		<c-rt:if test="${s.index<10}">0</c-rt:if>${s.index }
		</c-rt:set>
		<option ${param.endMinute==endMinute?'selected="selected"':'' } value="${endMinute }">${endMinute }</option>
		</c-rt:forEach>
		</select>
	</td>
	<td>退货原因：
	${pu:reqSet('reasonArray', pu:toArray(pu:emptyToNull(paramValues.reason))) }

	<br/><input type="checkbox" name="reason" value="订购错误" ${pu:isIn('订购错误', reasonArray)?'checked="checked"':'' }/>订购错误
	<br/><input type="checkbox" name="reason" value="商品发错" ${pu:isIn('商品发错', reasonArray)?'checked="checked"':'' }/>商品发错
	<br/><input type="checkbox" name="reason" value="商品或外包装破损" ${pu:isIn('商品或外包装破损', reasonArray)?'checked="checked"':'' }/>商品或外包装破损
	<br/><input type="checkbox" name="reason" value="商品不如预期" ${pu:isIn('商品不如预期', reasonArray)?'checked="checked"':'' }/>商品不如预期
	<br/><input type="checkbox" name="reason" value="商品属性不符" ${pu:isIn('商品属性不符', reasonArray)?'checked="checked"':'' }/>商品属性不符
	<br/><input type="checkbox" name="reason" value="价格比较贵" ${pu:isIn('价格比较贵', reasonArray)?'checked="checked"':'' }/>价格比较贵
	<br/><input type="checkbox" name="reason" value="与介绍不符" ${pu:isIn('与介绍不符', reasonArray)?'checked="checked"':'' }/>与介绍不符
	<br/><input type="checkbox" name="reason" value="改买其他款式" ${pu:isIn('改买其他款式', reasonArray)?'checked="checked"':'' }/>改买其他款式
	<br/><input type="checkbox" name="reason" value="商品未如期收到" ${pu:isIn('商品未如期收到', reasonArray)?'checked="checked"':'' }/>商品未如期收到
	<br/><input type="checkbox" name="reason" value="不会使用" ${pu:isIn('不会使用', reasonArray)?'checked="checked"':'' }/>不会使用
	<br/><input type="checkbox" name="reason" value="其他" ${pu:isIn('其他', reasonArray)?'checked="checked"':'' }/>其他
</td>
	<td></td>
</tr>
<tr>
	<td>
	<input type="button" onclick="${queryMethod}" value="查询"/>
	<input type="reset" value="重置"/>
	</td><td></td><td></td><td></td>
</tr>
</table>
</form>
<form name="exportAndBatchForm" method="post">
<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th></th>
				<th>订单编号</th>
				<th>退货编号</th>
				<th>会员</th>
				<th>商品名称</th>
				<th>退货金额</th>
				<th>退货原因</th>
				<th>退货期限</th>
				<th>状态</th>
				<th>功能</th>
				
			</tr>
		</thead>
		<tbody>
		<c-rt:forEach items="${results }" var="result">
		${pu:reqSet('sopsParams', null) }
		${pu:listAdd('sopsParams', result.serviceId) }
		${pu:reqSet('sops', pu:queryByHql('from ServiceOrderProduct where serviceId=?', pu:arrayGet('sopsParams'), null))  }
		
			<tr>
				<td>
				<c-rt:if test="${result.orderSt=='00'}">
				<c-rt:if test="${pu:isCRMManager(pu:username())}">
				<input class="serviceIds" type="checkbox" name="serviceId" value="${result.serviceId }"/>
				</c-rt:if>
				</c-rt:if>
				</td>
				<td>
				<a href="<c-rt:url value="/order/view.do?orderId=${result.orderId }"/>">
				${result.orderId }
				</a>
				</td>
				<td><a href="<c-rt:url value="/serviceOrder/page.do?iamlazy=detail&from=returnList&serviceId=${result.serviceId }"/>">${result.serviceId }</a></td>
				<td>${result.loginId }</td>
				<td style="text-align:left">
				<c-rt:forEach items="${sops }" var="sop">
					${sop.prodName }<br/>
					
					${pu:reqSet('order', pu:get('com.yaodian100.ec.order.entity.Orders', sop.orderId)) }
					<c-rt:forEach items="${order.orderProduct}" var="orderProduct">
					<c-rt:if test="${sop.orderProdId==orderProduct.orderProdId}">
					
					<c-rt:forEach items="${orderProduct.applyCampaigns}" var="ac">
	          	
	          	<p>
	          	<c-rt:if test="${ac.active}">
	          		<span class="type-4" style="color:red">优惠</span>
	          	</c-rt:if>
	          	<c-rt:if test="${!ac.active}">
	          		<span class="type-6"  style="color:gray">优惠</span>（不符合）
	          	</c-rt:if>
	          <c-rt:if test="${ac.campaignUrl!=null}">
	          	<a target="_blank" class="a-red" href="${ac.campaignUrl }">${ac.campaignName }</a>
	          	</c-rt:if>
	          	<c-rt:if test="${ac.campaignUrl==null}">
	          	
	          	${pu:reqSet('pc', pu:get('com.yaodian100.ec.campaign.entity.Campaign', ac.campaignUuid)) }
	          	
	          	${ac.campaignName }
	          	
	          	</c-rt:if>
	          	</p>
	          	<br/>
	          	</c-rt:forEach>
				</c-rt:if>
				</c-rt:forEach>
					
					<br/>
				</c-rt:forEach>
				</td>
				<td>${result.returnBenefit+result.returnBonus+result.returnCash+result.returnMyWallet+result.returnInstallmentFee }</td>
				<td>${result.reason }</td>
				<td>
				<c-rt:if test="${!empty sops[0].logisticFinalDt}">
				<fmt-rt:formatDate value="${pu:addDays(sops[0].logisticFinalDt, 7) }" pattern="yyyy-MM-dd"/>
				</c-rt:if>
				
				</td>
				<td>
				
				<c-rt:if test="${result.orderSt=='00' }">审核中</c-rt:if>
				<c-rt:if test="${result.orderSt=='10' }">申请中</c-rt:if>
				<c-rt:if test="${result.orderSt=='20' }">退款处理中</c-rt:if>
				<c-rt:if test="${result.orderSt=='30' }">异常</c-rt:if>
				<c-rt:if test="${result.orderSt=='50' }">逾期</c-rt:if>
				<c-rt:if test="${result.orderSt=='60' }">商品退回</c-rt:if>
				<c-rt:if test="${result.orderSt=='70' }">失败</c-rt:if>
				<c-rt:if test="${result.orderSt=='80' }">取消</c-rt:if>
				<c-rt:if test="${result.orderSt=='90' }">完成</c-rt:if>
				
				</td>
				<td>
				<c-rt:if test="${result.orderSt=='00'}">
				<input type="button" onclick="location.href='<c-rt:url value="/serviceOrder/confirmReturnProduct.do?serviceId=${result.serviceId }"/>'" value="审核成功"/>
				<input type="button" onclick="location.href='<c-rt:url value="/serviceOrder/cancelReturnProduct.do?serviceId=${result.serviceId }"/>'" value="审核失败"/>
				
				<%--
				<input type="button" onclick="doAR('<c-rt:url value="/serviceOrder/confirmReturnProduct.do?serviceId=${result.serviceId }"/>', 'main', 'queryForm')" value="审核成功"/>
				<input type="button" onclick="doAR('<c-rt:url value="/serviceOrder/cancelReturnProduct.do?serviceId=${result.serviceId }"/>', 'main', 'queryForm')" value="审核失败"/>
				--%>
				<input type="button" onclick="location.href='/ecadmin/serviceOrder/toReturnToChange.do?serviceId=${result.serviceId }'" value="退货转换货"/>
				</c-rt:if>
				</td>
			</tr>
		</c-rt:forEach>
		</tbody>
	</table>
	<c-rt:if test="${pu:isCRMManager(pu:username())}">
	<table class="tb-1" width="100%">
		<tr>
			<td style="text-align:left"><input type="button" value="汇出call out清单" onclick="exportCsv()"/><input type="button" value="整批确认退货单" onclick="batchConfirm()"/></td>
		</tr>
	</table>
	</c-rt:if>
	</form>
	<c-rt:if test="${empty results}">
	<table width="100%">
	<tr><td align="center">没有符合条件的资料！</td></tr>
	</table>
	</c-rt:if>
	<c-rt:set var="url">
	<c-rt:url value="/serviceOrder/page.do?iamlazy=returnList"/>
	</c-rt:set>
<pageable:Pageable url="${url}" formname="serviceOrderForm" escapeparams="iamlazy" key="index"></pageable:Pageable>
